﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using AdventureWorks.Entities;

namespace AdventureWorks.Helpers
{
	public static class ObjectCloner
	{
		public static T Clone<T>(this Entity source) where T : new()
		{
			T clone = new T();
			Type sourceType = source.GetType();
			PropertyInfo[] sourceProperties = sourceType.GetProperties();

			foreach (var property in sourceProperties)
			{
				property.SetValue(clone, property.GetValue(source, null), null);
			}

			return clone;
		}
	}
}
